import axios from "axios"
import {ElMessage} from "element-plus";
// 对axios进行封装
const  error_default = ()=>ElMessage.error('发生了一些问题！')
const failure_default = (msg)=>ElMessage.warning(msg)
function post(url,data,success,failure=failure_default,error=error_default){
    axios.post(url,data,{
        headers:{
            'Content-Type': 'application/x-www-form-urlencoded'
            //'Content-Type': 'application/json;charset=utf-8'
        },
        withCredentials:true
    }).then(({data})=>{
        //回调函数
        if (data.success){
            console.log(data)
            success(data.massage,data.status)
        }
        else{
            console.log(data)
            failure(data.massage)
        }
    }).catch(error)
}

function get(url,success,failure=failure_default,error=error_default){
    axios.get(url,{
        headers:{
            'Content-Type': 'application/x-www-form-urlencoded'
            //'Content-Type': 'application/json;charset=utf-8'
        },
        withCredentials:true
    }).then(({data})=>{
        //回调函数
        if (data.success){
            console.log(1)
            success(data.massage,data.status)
        }
        else{
            console.log(2)
            failure(data.massage,data.status)
        }
    }).catch(error)
}
export {post,get}
